import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '../layout/index'
import LayoutInner from '../layout/LayoutInner'
/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */

export const constantRoutes = [
  {//登录页面
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {//404页面
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {//首页
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '总览' },

    }]
  },
]

export const asyncRoutes = [
  {
    path: '/monitor',
    component: Layout,
    name: 'monitor',
    children: [
      {
        path: 'index',
        name: 'monitor-index',
        component: () => import('@/views/nav-monitor/index'),
        meta: { title: '运行监测' }
      }
    ]
  },
  {
    path: '/analysis',
    component: Layout,
    name: 'analysis',
    redirect: '/analysis/analysis-home',
    meta: { title: '汇总分析' },
    children: [
      {
        path: 'analysis-home',
        component: () => import('@/views/nav-analysis/home'),
        name: 'analysis-home',
        meta: { title: '汇总分析' }
      },
      {
        path: 'analysis-index',
        component: () => import('@/views/nav-analysis/index'),
        redirect: 'noRedirect',
        meta: { title: '管网指标分析' },
        hidden: true,
        children: [
        ]
      },
      {
        path: 'analysis-index',
        component: () => import('@/views/nav-analysis/index'),
        redirect: 'noRedirect',
        meta: { title: '生产数据分析' },
        hidden: true,
        children: [
          {
            path: 'slsj',
            component: () => import('@/views/nav-analysis/shengchanshuju/slsj'),
            name: 'slsj',
            meta: { title: '水量数据分析报表' }
          },
          {
            path: 'hdfx',
            component: () => import('@/views/nav-analysis/shengchanshuju/hdfx'),
            name: 'hdfx',
            meta: { title: '能耗分析报表' }
          },
          {
            path: 'ssh',
            component: () => import('@/views/nav-analysis/shengchanshuju/ssh'),
            name: 'ssh',
            meta: { title: '水损耗分析报表' }
          },
        ]
      },
      {
        path: 'analysis-index',
        component: () => import('@/views/nav-analysis/index'),
        redirect: 'noRedirect',
        meta: { title: '生产数据分析' },
        hidden: true,
        children: [
          {
            path: 'gzyc',
            component: () => import('@/views/nav-analysis/shebeiyunxing/gzyc'),
            name: 'gzyc',
            meta: { title: '故障异常分析' }
          }
        ]
      },
      {
        path: 'analysis-index',
        component: () => import('@/views/nav-analysis/index'),
        redirect: 'noRedirect',
        meta: { title: '财务数据分析' },
        hidden: true,
        children: [
          {
            path: 'cwsj',
            component: () => import('@/views/nav-analysis/caiwushuju/cwsj'),
            name: 'cwsj',
            meta: { title: '财务支出汇总' }
          }
        ]
      },
      {
        path: 'analysis-index',
        component: () => import('@/views/nav-analysis/index'),
        redirect: 'noRedirect',
        meta: { title: '工程数据分析' },
        hidden: true,
        children: [
          {
            path: 'gcsl',
            component: () => import('@/views/nav-analysis/gongchengshuju/gcsl'),
            name: 'gcsl',
            meta: { title: '工程数量统计' }
          }
        ]
      },
      {
        path: 'analysis-index',
        component: () => import('@/views/nav-analysis/index'),
        redirect: 'noRedirect',
        meta: { title: '营销数据分析' },
        hidden: true,
        children: [
          {
            path: 'sszl',
            component: () => import('@/views/nav-analysis/yingxiaoshuju/sszl'),
            name: 'sszl',
            meta: { title: '售水总量趋势分析' }
          },
          {
            path: 'khfb',
            component: () => import('@/views/nav-analysis/yingxiaoshuju/khfb'),
            name: 'khfb',
            meta: { title: '按用水类型分的客户分布' }
          },
          {
            path: 'sslb',
            component: () => import('@/views/nav-analysis/yingxiaoshuju/sslb'),
            name: 'sslb',
            meta: { title: '按用水类型分的客户分布' }
          },
        ]
      },
    ]
  },
  {
    path: '/decision',
    component: Layout,
    name: 'decision',
    children: [
      {
        path: 'decision-home',
        component: () => import('@/views/nav-decision/home'),
        name: 'decision-home',
        meta: { title: '辅助决策' }
      }
    ]
  },
  {
    path: '/dataSharing',
    component: Layout,
    name: 'analysis',
    redirect: '/dataSharing/dataSharing-home',
    meta: { title: '数据共享' },
    children: [
      {
        path: 'dataSharing-home',
        component: () => import('@/views/nav-dataSharing/home'),
        name: 'dataSharing-home',
        meta: { title: '数据共享' }
      },
      {
        path: 'retrieval',
        component: () => import('@/views/nav-dataSharing/index'),
        redirect: 'noRedirect',
        meta: { title: '数据检索' },
        hidden: true,
        children: [
          {
            path: 'classification',
            component: () => import('@/views/nav-dataSharing/retrieval/classification'),
            name: 'classification',
            meta: { title: '分类检索' }
          },
          {
            path: 'keyword',
            component: () => import('@/views/nav-dataSharing/retrieval/keyword'),
            name: 'keyword',
            meta: { title: '分类检索' }
          },
        ]
      },
      {
        path: 'downloading',
        component: () => import('@/views/nav-dataSharing/index'),
        redirect: 'noRedirect',
        meta: { title: '数据下载' },
        hidden: true,
        children: [
          {
            path: 'archives',
            component: LayoutInner,
            name: 'downloading-archives',
            meta: { title: '档案数据' },
            redirect: 'noRedirect',
            children:[
              {
                path: 'basicArchives',
                component: () => import('@/views/nav-dataSharing/downloading/archives/basicArchives'),
                name: 'downloading-archives-basicArchives',
                meta: { title: '水务基础档案' }
              },
            ]
          },
        ]
      },
      {
        path: 'interface',
        component: () => import('@/views/nav-dataSharing/index'),
        redirect: 'noRedirect',
        meta: { title: '数据接口' },
        hidden: true,
        children: [
          {
            path: 'measuredData',
            component: LayoutInner,
            name: 'interface-measuredData',
            meta: { title: '实测数据接口' },
            redirect: 'noRedirect',
            children:[
              {
                path: 'measuredData',
                component: () => import('@/views/nav-dataSharing/interface/measuredData/measuredData'),
                name: 'interface-measuredData-measuredData',
                meta: { title: '水务基础档案' }
              },
            ]
          },
        ]
      },
      {
        path: 'resources',
        component: () => import('@/views/nav-dataSharing/index'),
        redirect: 'noRedirect',
        meta: { title: '数据资源' },
        hidden: true,
        children: [
          {
            path: 'archives',
            component: LayoutInner,
            name: 'resources-archives',
            redirect: 'noRedirect',
            meta: { title: '档案数据' },
            children:[
              {
                path: 'basicArchives',
                component: () => import('@/views/nav-dataSharing/resources/archives/basicArchives'),
                name: 'resources-archives-basicArchives',
                meta: { title: '水务基础档案' }
              },
            ]
          },
        ]
      },
      {
        path: 'about',
        component: () => import('@/views/nav-dataSharing/index'),
        redirect: 'noRedirect',
        meta: { title: '关于平台' },
        hidden: true,
        children: [
          {
            path: 'briefIntroduction',
            component: () => import('@/views/nav-dataSharing/about/briefIntroduction'),
            name: 'briefIntroduction',
            meta: { title: '基础服务中心简介' }
          },{
            path: 'sharePlatform',
            component: () => import('@/views/nav-dataSharing/about/sharePlatform'),
            name: 'sharePlatform',
            meta: { title: '水务数据共享平台简介' }
          },{
            path: 'application',
            component: () => import('@/views/nav-dataSharing/about/application'),
            name: 'application',
            meta: { title: '离线水务资料使用申请' }
          },{
            path: 'detailedList',
            component: () => import('@/views/nav-dataSharing/about/detailedList'),
            name: 'detailedList',
            meta: { title: '共享平台已加载数据目录清单' }
          },{
            path: 'contactUs',
            component: () => import('@/views/nav-dataSharing/about/contactUs'),
            name: 'contactUs',
            meta: { title: '联系我们' }
          },
        ]
      },
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
